//
//  DeviceHelper.m
//  OCStarterProject
//
//  Created by huaya on 2025/10/2.
//

#import "DeviceHelper.h"
#import <sys/utsname.h>

@implementation DeviceHelper

+ (NSString *)deviceModel {
    struct utsname systemInfo;
    uname(&systemInfo);
    return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}

+ (NSString *)systemVersion {
    return [[UIDevice currentDevice] systemVersion];
}

+ (NSString *)appVersion {
    return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
}

+ (NSString *)appBuildVersion {
    return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
}

+ (NSString *)appName {
    return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
}

+ (NSString *)deviceIdentifier {
    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}

+ (CGFloat)screenWidth {
    return [UIScreen mainScreen].bounds.size.width;
}

+ (CGFloat)screenHeight {
    return [UIScreen mainScreen].bounds.size.height;
}

+ (CGFloat)statusBarHeight {
    return [[UIApplication sharedApplication] statusBarFrame].size.height;
}

+ (CGFloat)navigationBarHeight {
    return 44.0f;
}

+ (CGFloat)tabBarHeight {
    return 49.0f + [self safeAreaBottom];
}

+ (CGFloat)safeAreaTop {
    if (@available(iOS 11.0, *)) {
        UIWindow *window = [self keyWindow];
        if (window) {
            return window.safeAreaInsets.top;
        }
    }
    return 0;
}

+ (CGFloat)safeAreaBottom {
    if (@available(iOS 11.0, *)) {
        UIWindow *window = [self keyWindow];
        if (window) {
            return window.safeAreaInsets.bottom;
        }
    }
    return 0;
}

+ (BOOL)isIPhoneXSeries {
    if (@available(iOS 11.0, *)) {
        UIWindow *window = [self keyWindow];
        if (window) {
            return window.safeAreaInsets.bottom > 0;
        }
    }
    return NO;
}

+ (UIWindow *)keyWindow {
    return [UIApplication sharedApplication].delegate.window;
}

+ (BOOL)isIPad {
    return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
}

+ (BOOL)isLandscape {
    return UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
}

+ (NSString *)currentLanguage {
    return [[NSLocale preferredLanguages] firstObject];
}

+ (BOOL)isChinese {
    NSString *language = [self currentLanguage];
    return [language hasPrefix:@"zh"];
}

@end
